package com.bbtShop.api;

import com.bbtShop.aop.Login;
import com.bbtShop.core.model.*;
import com.bbtShop.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author manke
 * @Date 2020/10/30 15:16
 * @Version 0.0.1
 */
@Api(value = "sysUser", description = "系统用户控制")
@RestController
@RequestMapping("/sysUser")
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;

    @ApiOperation(value = "login", notes = "系统用户登录")
    @PostMapping("/login")
    public ApiResponse<Object> login(@RequestBody SysUser sysUser ){
        String token = sysUserService.login(sysUser);
        return ApiResponse.success(token);
    }
    @ApiOperation(value = "logout", notes = "系统用户登出")
    @PostMapping("/logout")
    public ApiResponse<Object> logout(){
        sysUserService.logout();
        return ApiResponse.success();
    }
    @ApiOperation(value = "register", notes = "系统用户注册")
    @PostMapping("/register")
    public ApiResponse<ProductRecode> register(@RequestBody SysUser sysUser ){
        sysUserService.register(sysUser);
        return ApiResponse.success();
    }

    @ApiOperation(value = "getMenu", notes = "获取菜单")
    @PostMapping("/getMenu")
    @Login
    public ApiResponse<List<UserMenuTree>> getMenu(){
        List<UserMenuTree> treeMenu = sysUserService.getMenu();
        return ApiResponse.success(treeMenu);

    }

    @ApiOperation(value = "loginInfo", notes = "获取用户登录信息")
    @PostMapping("/loginInfo")
    @Login
    public ApiResponse<Map<String,Object>> loginInfo(){
        return ApiResponse.success(sysUserService.loginInfo());

    }





}
